# -*- coding: utf-8 -*-
import calendar
import datetime

from dateutil.relativedelta import relativedelta

from demo_common_module.utils.excel_utils import ExcelUtils


class DayUtils(object):

    def __init__(self, year):
        self.month_days = {
            "01": 31,
            "02": 28,
            "03": 31,
            "04": 30,
            "05": 31,
            "06": 30,
            "07": 31,
            "08": 31,
            "09": 30,
            "10": 31,
            "11": 30,
            "12": 31,
        }
        if calendar.isleap(int(year)):  # 判断是否为闰年，为闰年的话，2月份为29天
            self.month_days["02"] = 29

    def get_year_month_day(self):
        current_time = datetime.datetime.now()
        year = current_time.year
        month = current_time.month
        day = current_time.day
        return year, month, day

    @staticmethod
    def get_relative_year_month_day(days=-1):
        current_time = datetime.datetime.now() + relativedelta(days=days)
        year = current_time.year
        month = current_time.month
        day = current_time.day
        month = ExcelUtils.makeup_quantity(month, 2)
        day = ExcelUtils.makeup_quantity(day, 2)
        return year, month, day

    def get_days(self, month):
        return self.month_days.get(month)


if __name__ == '__main__':
    print(DayUtils(2020).get_days("03"))
